package io;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Arrays;

/**
 * 当我们提高每次读写的数据量减少实际读写次数就可以提高读写效率
 */
public class CopyDemo2 {
    public static void main(String[] args) throws IOException {
        FileInputStream fis = new FileInputStream("image.jpeg");
        FileOutputStream fos = new FileOutputStream("image_cpq.jpeg");
        byte[] data = new byte[1024*10];//10kb
        int b;//记录每次实际读取到的字节量长度
        long start = System.currentTimeMillis();
        while ((b = fis.read(data))!=-1){
            fos.write(data,0,b);//构造参数0到b(实际长度)
        }
        System.out.println(Arrays.toString(data));
        long end = System.currentTimeMillis();
        System.out.println("已复制完成"+(end-start)+"ms");

    }
}
